import { ElMessage, ElLoading } from 'element-plus'
import { ref } from 'vue'
import { downloadImg } from '@/api/index'

export const myMessage = (type: string, message: string) => {
	ElMessage({
		type: 'success',
		message: message
	})
}

const loading = ref<any>(null)
export const showLoading = () => {
	loading.value = ElLoading.service({
		lock: true,
		text: 'Loading',
		background: 'rgba(0, 0, 0, 0.7)'
	})
}

export const closeLoading = () => {
	loading.value.close()
}

export const getImg = async (url: string) => {
	if (url) {
		const res = await downloadImg<Blob>({ name: url })
		// 使用 window.URL.createObjectURL 将图片流转为地址
		const path = window.URL.createObjectURL(new Blob([res as any], { type: 'image/png' }))
		return path
	}
}
